import login from '@/api/login';
import router from '@/router';
export const TOKEN_KEY = 'hcwl-Token'
// token设置
export const setToken = (token: string) => {
	localStorage.setItem(TOKEN_KEY, token)
}
// token获取
export const getToken = () => {
	const token = localStorage.getItem(TOKEN_KEY) // Cookies.get(TOKEN_KEY)
	if (token) return token
	else return false
}

// 登出的token清除与页面跳转设置
export const loginOut = async () => {
	await login.logoutByPlatform_API({ platform: 0 })
	router.push('/')
	localStorage.removeItem(TOKEN_KEY)
	localStorage.clear()
	sessionStorage.clear()
}

// 本地存储set
export const localStorageSET = (key: string, data: any) => {
	localStorage.setItem(key, JSON.stringify(data))
}

// 本地存储get
export const localStorageGET = (key: string) => {
	return localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key)!) : localStorage.getItem(key)
}

// 页面存储设置
export const SetsessionStorage = (key: string, data: any) => {
	sessionStorage.setItem(key, JSON.stringify(data))
}

// 页面存储读取
export const GetsessionStorage = (key: string) => {
	return sessionStorage.getItem(key) ? JSON.parse(sessionStorage.getItem(key) || "") : ""
}

//转化时分秒格式
export const convertSecondsToHMS = (seconds: any) => {
	const hours = Math.floor(seconds / 3600);
	const minutes = Math.floor((seconds % 3600) / 60);
	const remainingSeconds = seconds % 60;
	// return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
	return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
}